package c.x.jy.api.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import c.x.jy.common.annotation.HasPermissions;
import c.x.jy.common.exception.RRException;
import c.x.jy.common.utils.GetClassinfo;
import c.x.jy.dao.entity.SysUserEntity;
import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;

@Aspect
@Component
@Slf4j
public class HasPermissionsAspect {

 
	    @Before("execution(* c.x.jy.api.controller.*.*(..)) && @annotation(hasPermissions)")
	    public void before(JoinPoint joinPoint,HasPermissions hasPermissions) {
	     //   log.info("[Aspect1] before advise");
	        SysUserEntity user = (SysUserEntity) GetClassinfo.invoke(joinPoint.getTarget(),"getUser",   null);
	        if(!user.getPermissions().contains(hasPermissions.value())) {
	        	throw new RRException("无此权限！",HttpStatus.HTTP_FORBIDDEN );
	        }
	 
	 
	    }

}
